<?php
//session_start();
include_once "../config.inc.php";
//print_r($_POST);
//print_r($_SESSION);
//$uid = empty($_SESSION['id']) ? 0 : $_SESSION['id'];
$cid = empty($_POST['id']) ? 0 : $_POST['id'];
$eve = empty($_POST['eve']) ? 0 : $_POST['eve'];
//echo $cid;
//用户登陆状态时且传过来ID时删除

if ($uid > 0 and $cid > 0) {
	//删除操作
	if ($eve == 1) {
		$stmt = $pdo -> prepare("select id,uid from kp_test where id = ?");
		$stmt -> execute(array($cid));
		if ($arr = $stmt -> fetch(PDO::FETCH_ASSOC)) {
			//print_r($arr);
			if ($arr['uid'] == $uid) {
				$stmt = $pdo -> prepare("delete from kp_test where id=?");
				$stmt -> execute(array($cid));
				echo "1";
				exit();
			}
		}
		echo '0';
	//修改操作
	}else if($eve == 2){
		$val = empty($_POST['text']) ? '' : $_POST['text'];
		$stmt = $pdo -> prepare("select id,uid from kp_test where id = ?");
		//echo  "select id,uid from kp_test where id = ?".$cid;
		$stmt -> execute(array($cid));
		if ($arr = $stmt -> fetch(PDO::FETCH_ASSOC)) {
			//print_r($arr);
			if ($arr['uid'] == $uid) {
				$stmt = $pdo -> prepare("update kp_test set content=? where id=?");
				//echo 'cccccccccccccccc';
				$stmt -> execute(array($val,$cid));
				echo "1";
				exit();
			}
		}
		echo '0';
	}
}
?>